﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HCommon;
using System.Threading;
namespace eStock
{
    public partial class frmMDIMain : Form
    {
        public frmMDIMain()
        {
            InitializeComponent();
        }

        //private void frmMDIMain_Load(object sender, EventArgs e)
        //{
        //    frmBGImage bgImage = new frmBGImage();
        //    bgImage.MdiParent = this;
        //    bgImage.Show();
        //}

        private void ShowForm(Form frmShow, bool isFullScreen)
        {
            try
            {
                this.MdiChildren.Contains(frmShow);
                foreach (Form frm in this.MdiChildren)
                {
                    if (frmShow.Name == frm.Name)
                    {
                        frmShow.StartPosition = FormStartPosition.CenterScreen;
                        return;
                    }
                }
                frmShow.StartPosition = FormStartPosition.CenterScreen;
                frmShow.MdiParent = this;
                if (isFullScreen)
                {
                    frmShow.WindowState = FormWindowState.Maximized;
                }
                frmShow.Show();
                frmShow.BringToFront();
            }
            catch (Exception ex)
            {
                Common.GhiLog("btnLogin_Click", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }
        }

        private void tsbUser_Click(object sender, EventArgs e)
        {
            ShowForm(new frmUser(), false);
        }

        private void tsbItems_Click(object sender, EventArgs e)
        {
            ShowForm(new frmItems(), false);
        }

        private void tsbExit_Click(object sender, EventArgs e)
        {
            DialogResult ds = MessageBox.Show(this, "Bạn có chắc chắn muốn tắt chương trình?", "Thông báo", MessageBoxButtons.YesNo);
            if (ds == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            Application.Exit();
        }

        private void tsbImExport_Click(object sender, EventArgs e)
        {
            ShowForm(new frmImExport_List(), false);
        }

        private void tsmStockReport_Click(object sender, EventArgs e)
        {
            ShowForm(new frmStockReport(), false);
        }

        private void tsmStockReportSum_Click(object sender, EventArgs e)
        {
            ShowForm(new frmStockReportSum(), false);
        }

        private void tsbCustomer_Click(object sender, EventArgs e)
        {
            ShowForm(new frmCustomer(), false);
        }

        private void tsbQuote_Click(object sender, EventArgs e)
        {
            ShowForm(new frmQuote(), false);
        }


        private void frmMDIMain_Load(object sender, EventArgs e)
        {
            try
            {
                if (Settings.myGroup == "GRP00001") 
                {
                    tsbUser.Visible = true;
                }
            }
            catch { }
        }

        private void tsbLogout_Click(object sender, EventArgs e)
        {
            try
            {
                Thread tienTrinh = new Thread(new ThreadStart(StartLogout));
                tienTrinh.SetApartmentState(ApartmentState.STA);
                tienTrinh.Start();
            }
            catch (Exception ex)
            {
                Common.GhiLog("btnLogin_Click", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }
        }

        private void StartLogout() 
        {
            this.Close();
            Application.Run(new frmLogin());
        }
    }
}
